package top.itmeans.yes.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.itmeans.yes.entity.OrderReturnReason;
import top.itmeans.yes.mapper.OrderReturnReasonMapper;
import top.itmeans.yes.service.OrderReturnReasonService;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 退货原因表 服务实现类
 * </p>
 *
 * @author Yiming.Cao
 * @since 2022-04-28
 */
@Service
public class OrderReturnReasonServiceImpl extends ServiceImpl<OrderReturnReasonMapper, OrderReturnReason> implements OrderReturnReasonService {

    @Resource
    private OrderReturnReasonMapper orderReturnReasonMapper;

    @Override
    public int create(OrderReturnReason returnReason) {
        returnReason.setCreateTime(LocalDateTime.now());
        return orderReturnReasonMapper.insert(returnReason);
    }

    @Override
    public int update(Long id, OrderReturnReason returnReason) {
        returnReason.setId(id);
        return orderReturnReasonMapper.updateById(returnReason);
    }

    @Override
    public int delete(List<Long> ids) {
        return orderReturnReasonMapper.deleteBatchIds(ids);
    }

    @Override
    public Page<OrderReturnReason> list(Integer pageSize, Integer pageNum) {
        Page<OrderReturnReason> page = new Page<>(pageNum,pageSize);
        return this.page(page);
    }

    @Override
    public int updateStatus(List<Long> ids, Integer status) {
        if(!status.equals(0)&&!status.equals(1)){
            return 0;
        }
        int count = 0;
        for (Long id: ids) {
            OrderReturnReason orderReturnReason = new OrderReturnReason();
            orderReturnReason.setId(id);
            orderReturnReason.setStatus(4);
            count += orderReturnReasonMapper.updateById(orderReturnReason);
        }
        return count;
    }
}
